﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Org.BouncyCastle.Utilities.Encoders;

namespace Common.Entitys.CommonLogs
{
    /// <summary>
    /// 初始化日志
    /// </summary>
    [Serializable]
    public class InitLogEntity : LogEntity
    {
        public InitLogEntity(string message)
        {
            Content = message;
        }

        public static implicit operator InitLogEntity(string message)
        {
            return new InitLogEntity(message);
        }

        public override string GetLogFiledName()
        {
            return $"初始化.txt";
        }
    }

    /// <summary>
    /// 警告日志
    /// </summary>
    [Serializable]
    public class WarnLogEntity : LogEntity
    {

        public WarnLogEntity(string message)
        {
            Content = message;
        }

        public static implicit operator WarnLogEntity(string message)
        {
            return new WarnLogEntity(message);
        }

        public override string GetLogFiledName()
        {
            return $"警告.txt";
        }
    }

    /// <summary>
    /// 警告日志
    /// </summary>
    [Serializable]
    public class HighWarnLogEntity : LogEntity
    {

        public HighWarnLogEntity(string message)
        {
            Content = message;
        }

        public static implicit operator HighWarnLogEntity(string message)
        {
            return new HighWarnLogEntity(message);
        }

        public override string GetLogFiledName()
        {
            return $"高级警告.txt";
        }
    }

    /// <summary>
    /// 初始化日志
    /// </summary>
    [Serializable]
    public class InfoLogEntity : LogEntity
    {
        public InfoLogEntity(string message)
        {
            Content = message;
        }

        public static implicit operator InfoLogEntity(string message)
        {
            return new InfoLogEntity(message);
        }

        public override string GetLogFiledName()
        {
            return $"信息.txt";
        }
    }

    /// <summary>
    /// 异常日志
    /// </summary>
    [Serializable]
    //[DelimitedRecord("|")]
    public class ErrorLogEntity : LogEntity
    {

        public ErrorLogEntity(Exception exception)
        {
            Content = exception.StackTrace;
        }

        public ErrorLogEntity(string content)
        {
            Content = content;
        }

        public ErrorLogEntity(string content,Exception exception)
        {
            string s = exception.StackTrace;
            if (string.IsNullOrEmpty(s))
            {
                s = exception.Message;
            }
            Content = $"{content}  异常信息   {s}";
        }

        public static implicit operator ErrorLogEntity(Exception exception)
        {
            return new ErrorLogEntity(exception);
        }

        public static implicit operator ErrorLogEntity(string content)
        {
            return new ErrorLogEntity(content);
        }

        public override string GetLogFiledName()
        {
            return $"异常.txt";
        }
    }

    /// <summary>
    /// 实时日志(下位机)
    /// </summary>
    [Serializable]
    public class RealTimeLowLogEntity : LogEntity
    {
        public RealTimeLowLogEntity()
        {

        }

        public RealTimeLowLogEntity(byte[] bytes)
        {
            Content = Hex.ToHexString(bytes);
        }

        public static implicit operator RealTimeLowLogEntity(byte[] bytes)
        {
            return new RealTimeLowLogEntity(bytes);
        }

        public override string GetLogFiledName()
        {
            return $"下位机实时数据.txt";
        }

        public override string ToString()
        {
            return JsonConvert.SerializeObject(this)+"\r\n";
        }
    }

    /// <summary>
    /// 机械臂实时数据(
    /// </summary>
    [Serializable]
    public class RealTimRobot : LogEntity
    {
        public double[] JointPoints;

        public RealTimRobot(double[] jointPoints)
        {
            JointPoints = jointPoints;
        }

        public static implicit operator RealTimRobot(double[] jointPoints)
        {
            return new RealTimRobot(jointPoints);
        }

        public override string GetLogFiledName()
        {
            return $"机械臂实时数据.txt";
        }

        public override string ToString()
        {
            return JsonConvert.SerializeObject(this)+"\r\n";
        }
    }

    [Serializable]
    public class FunctionLog : LogEntity
    {
        /// <summary>
        /// 方法名称
        /// </summary>
        public string FunctionName;

        /// <summary>
        /// 是否有异常
        /// </summary>
        public bool HaveExcption = false;

        /// <summary>
        /// 异常内容
        /// </summary>
        public string ExcptionStrack = "";

        /// <summary>
        /// 入参
        /// </summary>
        public List<string> LisParas = new List<string>();

        /// <summary>
        /// 进入时间
        /// </summary>
        public DateTime EntryTime;

        /// <summary>
        /// 退出时间
        /// </summary>
        public DateTime ExitTime;

        /// <summary>
        /// 返回值
        /// </summary>
        public string ReturnValue="";

        public override string GetLogFiledName()
        {
            if (HaveExcption)
            {
                return $"方法异常数据.txt";
            }
            else
            {
                return $"方法数据.txt";
            }
           
        }

        public override string ToString()
        {
            return JsonConvert.SerializeObject(this) +"\r\n";
        }
    }




}
